from PIL import Image
from airtest.aircv import *
from pytesseract import pytesseract
from basic.device.Android import Android
from airtest.core.api import *

class dataSecretaryPage(Android):


    @classmethod
    def clickData(self):
        self.poco(text='数据秘书').click()


    @classmethod
    def getData(self):
        sleep(3)
        dataText = self.poco(text='个人数据(完成度)').wait(2)
        if dataText.exists():
            return True

    # 获取页面文字
    @classmethod
    def getText(self):


         # 局部截图
        screen = G.DEVICE.snapshot()
        local = aircv.crop_image(screen, (380, 426, 675, 698))

        # 保存截图
        pil_image = cv2_2_pil(local)
        pil_image.save("D:/dd/screen.png", quality=99, optimize=True)
        sleep(2)

        # 读取截图并识别文字，识别中文加参数lang='chi_sim'
        image = Image.open('D:/dd/screen.png')
        dataText = pytesseract.image_to_string(image, lang='chi_sim')
        print(dataText)

        return dataText

